CC = gcc
FLAGS = -Wall -O2

is_64=$(shell s=`uname -m`; if (echo $$s | grep x86_64 > /dev/null); then echo 1; fi)

# AMD
PATH_TO_AMD_INC=/opt/AMDAPP/include/
ifeq ($(is_64), 1)
PATH_TO_AMD_LIB=/opt/AMDAPP/lib/x86_64/
else
PATH_TO_AMD_LIB=/opt/AMDAPP/lib/x86/
endif

# NVIDIA
PATH_TO_NVIDIA_INC=/usr/local/cuda/include/
PATH_TO_NVIDIA_LIB=/usr/lib/

all: jrm.amd jrm.nvidia

jrm.amd:amd.o
	$(CC) $(CFLAGS) -L$(PATH_TO_AMD_LIB) -Wl,-rpath,$(PATH_TO_AMD_LIB) -o jrm.amd main.c jrm.o -lOpenCL

amd.o: jrm.c jrm.h
	$(CC) $(FLAGS) -I$(PATH_TO_AMD_INC) -c jrm.c

jrm.nvidia:nvidia.o
	$(CC) $(CFLAGS) -L$(PATH_TO_NVIDIA_LIB) -o jrm.nvidia main.c jrm.o -lOpenCL

nvidia.o: jrm.c jrm.h
	$(CC) $(FLAGS) -I$(PATH_TO_NVIDIA_INC) -c jrm.c

clean:
	rm -f *.amd *.nvidia *.o
